package com.creditease.tmsp.modules.sys.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.Transient;

/**
 * 
 * @Description：资源Entity
 * @author：
 * @CreateDate：2014年6月18日下午6:19:25 
 * @Company:
 * @version V1.0
 */
public class SysResource {
    
	private String id;            //ID
    private String parentId;      //父级菜单ID
    private String parentIds;     //所有父级ID
    private String name;          //名称
    private String href;          //链接
    private String target;        //目标
    private String icon;          //图标
    private Integer sort;         //排序
    private String isShow;        //是否显示
    private String permission;    //权限标识
    private String creatorId;     //创建人ID
    private Date createTime;      //创建时间
    private String remarks;       //备注
    private String delFlag;       //删除标记

    public String getId() {
        return id;
    }

	public void setId(String id) {
        this.id = id == null ? null : id.trim();
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId == null ? null : parentId.trim();
    }

    public String getParentIds() {
        return parentIds;
    }

    public void setParentIds(String parentIds) {
        this.parentIds = parentIds == null ? null : parentIds.trim();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    public String getHref() {
        return href;
    }

    public void setHref(String href) {
        this.href = href == null ? null : href.trim();
    }

    public String getTarget() {
        return target;
    }

    public void setTarget(String target) {
        this.target = target == null ? null : target.trim();
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon == null ? null : icon.trim();
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public String getIsShow() {
        return isShow;
    }

    public void setIsShow(String isShow) {
        this.isShow = isShow == null ? null : isShow.trim();
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission == null ? null : permission.trim();
    }

    public String getCreatorId() {
        return creatorId;
    }

    public void setCreatorId(String creatorId) {
        this.creatorId = creatorId == null ? null : creatorId.trim();
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks == null ? null : remarks.trim();
    }

    public String getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(String delFlag) {
        this.delFlag = delFlag == null ? null : delFlag.trim();
    }
    
    private SysResource parent;	// 父级菜单
    public SysResource getParent() {
		return parent;
	}
	public void setParent(SysResource parent) {
		this.parent = parent;
	}    
    
	
	public SysResource(){
		super();
		this.sort = 30;
	}
	public SysResource(String id){
		this();
		this.id = id;
	}
	
	@Transient
	public boolean isRoot(){
		return isRoot(this.id);
	}
	
	@Transient
	public static boolean isRoot(String id){
		return id != null && id.equals("1");
	}
	
	public static void sortList(List<SysResource> list, List<SysResource> sourcelist, String parentId){
		for (int i=0; i<sourcelist.size(); i++){
			SysResource e = sourcelist.get(i);
			if (e.getParentId()!=null&& e.getParentId().equals(parentId)){
				list.add(e);
				// 判断是否还有子节点, 有则继续获取子节点
				for (int j=0; j<sourcelist.size(); j++){
					SysResource child = sourcelist.get(j);
					if (child.getParentId()!=null&& child.getParentId().equals(e.getId())){
						sortList(list, sourcelist, e.getId());
						break;
					}
				}
			}
		}
	}
    
}